<!DOCTYPE>
<html>
	<head>
<?
	//先通过dirname(__FILE__)获取到当前文件绝对路径，然后再按具体情况用..去控制找到templates文件夹下的header.php
	include dirname(__FILE__)."/../templates/header.php";
?>
	<link type="text/css" rel="stylesheet" href="<? echo base_url() ?>css/admin/content.css" />

	<script charset="utf-8" src="<? echo base_url() ?>js/kindeditor/kindeditor.js"></script>
	<script charset="utf-8" src="<? echo base_url() ?>js/kindeditor/lang/zh_CN.js"></script>
	<link rel="stylesheet" href="<? echo base_url() ?>js/kindeditor/plugins/code/prettify.css" />
	<script charset="utf-8" src="<? echo base_url() ?>js/kindeditor/plugins/code/prettify.js"></script>

	<script type="text/javascript">

		var kindEditor;

		var kindEditorSetting = {
			cssPath : '<? echo base_url() ?>js/kindeditor/plugins/code/prettify.css',
			uploadJson : '<? echo base_url() ?>upload/upload_json.php',
			fileManagerJson : '<? echo base_url() ?>upload/file_manager_json.php',
			allowFileManager : true
		};

		KindEditor.ready(function(K) {
			kindEditor = K.create('#content',kindEditorSetting);
			prettyPrint();
		});

		$(document).ready(
			function(){

				//保存按钮
				$("#btnSub").click(
					function(){
						if(! abhxCommonValidate($("#updateForm"))){
							return false;
						}

						//让隐藏文本框获得编辑器中的内容
						$("#content").val(kindEditor.html());

						console.log($("#updateForm").get(0).submit);

						$("#updateForm").get(0).submit();
					}
				);

				$("#btnCancel").click(
					function(){
						document.location.href = "<? echo base_url() ?>index.php/content/toList/<? echo $category_id ?>/no" ;
					}
				);
			}
		);

	</script>

	</head>

	<body>

<form id="updateForm" action="<? echo base_url() ?>index.php/content/createOrUpdate" method="post" accept-charset="utf-8" enctype="multipart/form-data">

  <input type='hidden' name='id' value='<? echo isset($cms_content->id) ? $cms_content->id : "" ?>'/>
  <input type="hidden" name="category_id" value="<? echo $category_id ?>"/>

  <table cellspacing="1" cellpadding="3" class="title title2">
	<tr>
		<td><? echo isset($cms_content->id) ? "编辑" : "添加" ?>文章</td>
	</tr>
  </table>
	<dl>
		<dt>
			<label for="title">标题</label>
		</dt>
		<dd>
			<input type='text' value='<?php echo isset($cms_content->title) ? $cms_content->title : ""?>' name='title'
			abhxValid="true" abhxValidType="text,required" abhxValidName="标题"/>
		</dd>
	</dl>
	<dl>
		<dt>
			<label for="recommend">是否推荐</label>
		</dt>
		<dd>
			<input type="checkbox" name="recommend" value="1" <? if(isset($cms_content)){ if($cms_content ->recommend == 1){ echo "checked" ; } }?>/>
		</dd>
	</dl>
	<dl>
		<dt>
			<label for="order_no">显示顺序</label>
		</dt>
		<dd>
			<input type="text" name="order_no" value="<?php echo isset($cms_content->order_no) ? $cms_content->order_no : $maxOrderNo ?>"
			abhxValid="true" abhxValidType="int,required" abhxValidName="排序"/>
		</dd>
	</dl>
	<?
	//如果是栏目类型是图片
	if($category_type == "3"){
	?>
		<dl>
			<dt>
				<label for="order_no">缩略图标</label>
			</dt>
			<dd>
				<?
					if(isset($cms_content->picture_url)){
				?>
				<img src="<? echo base_url() . "upload/image/" . $cms_content->picture_url ?>" width="100" height="100"/>
				<?
					}
				?>
				<input type="file" name="picture"/>
			</dd>
		</dl>
	<? } ?>
	<dl>
		<dt>
			<label for="content">文章内容</label>
		</dt>
		<dd>
			<textarea id='content' name='content' style='width:600px;height:300px;'><? echo isset($cms_content->content) ? htmlspecialchars($cms_content->content) : ""?></textarea>
		</dd>
	</dl>
	<div class="clear"></div>
	<div class="contentDiv">
		<input type='button' id="btnSub" value=' 保 存 ' />&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value=' 返回列表 ' id="btnCancel"/>
	</div>

</form>

</body>

<? if($info != "no"){
?>
<script type='text/javascript'>
	alert("<? echo $info ?>");
</script>
<? } ?>


</html>
